package com.chixing.controller;

import com.chixing.entity.Car;
import com.chixing.entity.CarBrand;
import com.chixing.entity.LoginCustomer;
import com.chixing.service.ICarService;
import com.chixing.service.impl.CarBrandServiceImpl;
import com.chixing.util.Result;
import com.chixing.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class IndexContoller {
    @Autowired
    private ICarService carService;

    @GetMapping("loadIndexData")
    public Result loadIndexData(HttpServletRequest request){
        String token = request.getHeader("token");
        System.out.println("index token:" + token);

        // ajax 请求后端加载: 1. 用户登录数据  2. 热门车辆数据
        LoginCustomer loginCustomer = TokenUtil.parseToken(token);

        //(3)商品热数据
        List<Car> hotProList = carService.getHotDiscountProduct();
        Map<String,Object> map =  new HashMap<>();
        map.put("loginCustomer",loginCustomer);
        map.put("carList",hotProList);


        return Result.success("ok",map);
    }
}
